<template>
  <div class="shop-car-item">
    <div class="item-title">
      <img src="~assets/img/tabBar/shop_city_active.svg" alt="">
      <span>{{goodsItem.name}}</span>
    </div>
    <div class="item-main">
      <div class="item-choose" @click="changeChecked">
        <img src="~assets/img/common/goodChoose.svg" alt="" :class="{isChecked: goodsItem.isChecked}">
      </div>
      <div class="item-img">
        <img :src="goodsItem.image" alt="">
      </div>
      <div class="item-text">
        <p>{{goodsItem.title}}</p>
        <div class="item-text-bottom">
          <span>{{'￥' + goodsItem.price}}</span>
          <i>{{'x' + goodsItem.quantity}}</i>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "ShopCarItem",
  props: {
    goodsItem: {
      type: Object,
      default() {
        return {}
      }
    }
  },
  methods: {
    changeChecked() {
      this.$store.commit('changeItemChecked', this.goodsItem);
      this.$store.dispatch('checkGoodsIsChose');
    }
  }
}
</script>

<style scoped lang="less">
  .shop-car-item {
    background-color: #ffffff;
    margin: 10px 0;
    border-radius: 10px;
  }
  
  .item-title {
    padding-left: 10%;
    height: 50px;
    line-height: 50px;
    color: #000000;
    img {
      height: 24px;
      width: 24px;
      vertical-align: middle;
      margin-right: 4px;
    }
  }

  .item-main {
    display: flex;
    height: 120px;
    padding-bottom: 10px;
  }

  .item-choose {
    flex: 10%;
    height: 100%;
    line-height: 120px;
    text-align: center;
    img {
      width: 24px;
      height: 24px;
      padding: 4px;
      border-radius: 12px;
      vertical-align: middle;
      border: 2px solid #cccccc;
    }
    .isChecked {
      background-color: var(--color-high-text);
      border: none;
    }
  }

  .item-img {
    flex: 30%;
    position: relative;
    height: 100%;
    border-radius: 4px;
    overflow: hidden;
    img {
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      width: 100%;
    }
  }

  .item-text {
    flex: 60%;
    position: relative;
    padding: 0 10px;
    p {
      color: #000000;
      word-break: break-all;
      overflow: hidden;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;
      margin-bottom: 5px;
      font-size: 16px;
    }
  }

  .item-text-bottom {
    display: flex;
    position: absolute;
    left: 10px;
    right: 10px;
    bottom: 10px;
    font-size: 20px;
    span {
      flex: 80%;
      color: var(--color-high-text);
    }
    i {
      flex: 20%;
      font-style: normal;
      text-align: center;
      color: #000000;
      background-color: #f8f8f8;
      border: 1px solid #eeeeee;
      border-radius: 5px;
    }
  }
</style>